package com.yeskery.nut.web.demo.config;

import com.yeskery.nut.annotation.bean.Bean;
import com.yeskery.nut.annotation.bean.Configuration;
import com.yeskery.nut.core.Method;
import com.yeskery.nut.extend.oauth.OAuthPluginBuilds;
import com.yeskery.nut.plugin.Plugin;
import com.yeskery.nut.web.demo.biz.OAuthBiz;
import com.yeskery.nut.web.demo.biz.OAuthClientBiz;

/**
 * OAuthConfig
 * @author YESKERY
 * 2024/11/4
 */
@Configuration
public class OAuthConfig {

    @Bean
    public Plugin OAuthPlugin(OAuthClientBiz oAuthClientBiz, OAuthBiz oAuthBiz) {
        return OAuthPluginBuilds.buildAuthorizationCodeServerSessionPlugin("/oauth/login", Method.GET,
                oAuthClientBiz::checkClientAuthorizationCodeAuthorizeRequest,
                oAuthClientBiz::checkClientAuthorizationCodeGrantRequest, null,
                oAuthBiz::getCurrentOAuthUserName);
    }
}
